#ifndef BMPOUTPUT_H
#define BMPOUTPUT_H

#include "output.h"

class BmpOutput : public Output
{
public:
	BmpOutput(const std::string& path, uint width, uint height);
	~BmpOutput();

	virtual void init();
	virtual void close();
	virtual void set_pixel(uint x, uint y, const Color& c);

private:
#pragma pack(1)
	struct BmpColor
	{
		byte b, g, r;
	};

	struct BmpFileHeader
	{
		// Must always be set to 'BM' (19778) to declare that this is a .bmp-file 
		uint16 type;
		// Specifies the size of the file in bytes 
		uint size;
		// Must always be set to zero 
		uint16 reserved1;
		// Must always be set to zero 
		uint16 reserved2;
		// Specifies the offset from the beginning of the file to the bitmap data 
		uint offset;
	};

	struct BmpInfoHeader
	{
		// Specifies the size of the BmpInfoHeader structure, in bytes. Always 40. 
		uint size;
		// Width of the image, in pixels 
		uint width;
		// Height of the image, in pixels 
		uint height;
		// Number of planes of the target device, must be set to zero 
		uint16 planes;
		// Bits per pixel 
		uint16 bpp;
		// Type of compression, usually set to zero (no compression) 
		uint compression;
		// Size of the image data, in bytes. If there is no compression, it is valid to set this member to zero 
		uint image_size;
		// Horizontal pixels per meter on the designated targer device, usually set to zero 
		uint h_resolution;
		// Vertical pixels per meter on the designated targer device, usually set to zero 
		uint v_resolution;
		// Number of colors used in the bitmap, if set to zero the number of colors is calculated using the bpp member 
		uint colors;
		// Number of colors that are 'important' for the bitmap, if set to zero, all colors are important. 
		uint important_colors;
	};
#pragma pack()

	void write();

	const std::string path;
	BmpColor* buffer;
};

#endif
